#include "LoginDialog.h"
#include <QDebug>
LoginDialog::LoginDialog (void)
{
	//界面初始化
	setupUi (this);
	//点击ok按钮发送accepted
	connect (m_btnBox, SIGNAL(accepted()), 
			this, SLOT(onAccepted()));
	//点击cancle按钮发送rejected
	connect (m_btnBox, SIGNAL(rejected()),
			this, SLOT(onRejected()));
}
void LoginDialog::onAccepted (void) 
{
	//qDebug("ok"); 
	//如果用户输入"andy lau" "123456" 提示成功登录
	//否则提示登录失败
	if (m_editUserName->text() == "andy lau" && m_editPassword->text() == "123456") {
		qDebug ("登录成功");
		qDebug ("进入主界面...");
		close ();
	} else {
		QMessageBox msgBox(QMessageBox::Critical, 
				windowTitle(), "用户名或密码错误", 
				QMessageBox::Ok,
				this
				);
		//显示提示框, 并进入事件循环, 点击消息框按钮会自动退出
		msgBox.exec ();
	}
}
void LoginDialog::onRejected (void) 
{
	//qDebug() << "cancel";
	QMessageBox msgBox(QMessageBox::Question, 
			windowTitle(), "确定要退出?", 
			QMessageBox::Yes|QMessageBox::No,
			this
			);
	if (msgBox.exec() == QMessageBox::Yes) {
		close ();
	}
}
